package com.houfukude.NoteList;

import java.io.File;
import java.util.List;

import com.houfukude.xtestmgr.R;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class NoteListAdapter extends BaseAdapter {

	private List<ItemValue> list = null;
	private ItemValue value = null;
	private ItemView item = null;
	private Context context;

	public NoteListAdapter(List<ItemValue> list, Context context) {
		super();
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {

		return list.size();
	}

	@Override
	public Object getItem(int arg0) {

		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {

		
		value = list.get(position);
		item = new ItemView();
		view = LayoutInflater.from(context).inflate(R.layout.list_item, null);
		
		// 新建一个item与list_item.xml绑定！
		item.setDay((TextView) view.findViewById(R.id.item_day));
		item.setTime((TextView) view.findViewById(R.id.item_time));
		item.setPrivew((ImageView) view.findViewById(R.id.item_preview));
		item.setTitle((TextView) view.findViewById(R.id.item_title));
		item.setDescription((TextView) view.findViewById(R.id.item_description));
		item.setExt1((ImageView) view.findViewById(R.id.item_ext1));
		item.setExt2((ImageView) view.findViewById(R.id.item_ext2));
		item.setExt3((ImageView) view.findViewById(R.id.item_ext3));
		item.setLink((TextView) view.findViewById(R.id.item_link));
		view.setTag(value);

		// 对绑定好了的view进行初始化操作
		item.getDay().setText(value.getDay());
		item.getTime().setText(value.getTime());

		if (value.getPriview() != null) {
			item.getPrivew().setImageURI(Uri.fromFile(new File(value.getPriview())));
		}

		item.getTitle().setText(value.getTitle());

		item.getDescription().setText(value.getDescription());

		if (value.getExt1()==0) {
			item.getExt1().setVisibility(View.VISIBLE);
		} else {
			item.getExt1().setVisibility(View.GONE);
		}
		if (value.getExt2()==0) {
			item.getExt2().setVisibility(View.VISIBLE);
		} else {
			item.getExt2().setVisibility(View.GONE);
		}

		if (value.getExt3()==0) {
			item.getExt3().setVisibility(View.VISIBLE);
		} else {
			item.getExt3().setVisibility(View.GONE);
		}

		item.getLink().setText(value.getLink());
		return view;
	}

}
